import { getQuestionApi, addQuestionApi, deleteQuestionApi, updateQuestionApi } from '../../api/audit/index'
import qs from 'qs'
export const state = () => ({
  list: []
})

export const mutations = {
  SET_LIST(state, list) {
    state.list = list
  }
}

export const actions = {
  // 渲染列表
  async getQuestion({ commit }) {
    const r = await getQuestionApi()
    //   console.log(r);
    commit('SET_LIST', r.data)

    //   commit('SET_LIST', r.data.reverse())
  },
  // 新增
  async addQuestion({ dispatch }, form) {
    // const options  = form.options.map( (v,i) =>{
    //    return qs.stringify(v)
    // } )
    // const lx = { ...form, answers: form.answers.sort().join(''), uid: 1, options:options }
    // console.log(lx)
    // console.log(options)
    if (form.id) {
      await updateQuestionApi(form)
    } else {
      await addQuestionApi(form)
    }



    dispatch('getQuestion')
  },
  // 删除
  async deleteQuestion({ dispatch }, id) {
    await deleteQuestionApi({ id })
    dispatch('getQuestion')
  },
  // 修改
  // async updataQuestion({ dispatch }, form) {
  //   const r = await updateQuestionApi(form)
  //   dispatch('getQuestion')
  // },


}

export const getters = {}